package com.ruoyi.blog.util;

import org.springframework.security.core.Authentication;

import javax.servlet.http.HttpServletRequest;

public class UserInfoUtil {

    public static String getUsername(Authentication authentication) {
        if (authentication!=null) {
            String name = authentication.getName();
            return name;
        } else {
            return null;
        }
    }

    public static String getIp(HttpServletRequest request) {
        String remoteAddr = request.getRemoteAddr();
        return remoteAddr;
    }

    public static String getUser(HttpServletRequest request) {
        String remoteUser = request.getRemoteUser();
        return remoteUser;
    }

    public static String getHost(HttpServletRequest request) {
        String remoteHost = request.getRemoteHost();
        return remoteHost;
    }

    public static Integer getPort(HttpServletRequest request) {
        int remotePort = request.getRemotePort();
        return remotePort;
    }
}
